from manim import *



class math4(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        #设置横线
        for i in range(60*2+1):       
            dot1=Dot([-500,5*(i-60),0]).set_opacity(0.5)
            dot2=Dot([500,5*(i-60),0]).set_opacity(0.5)
            if i==6:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
                
            else:
                line1=Line(dot1,dot2).set_color(WHITE).set_opacity(0.5)
               
            self.add(dot1,dot2,line1)
        #设置竖线
        for i in range(100*2+1):        
            dot3=Dot([(i-100)*5,-300,0]).set_opacity(0.5)
            dot4=Dot([(i-100)*5,300,0]).set_opacity(0.5)
            if i==10:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
                
            else:
                line2=Line(dot3,dot4).set_color(WHITE).set_opacity(0.5)
            self.add(dot3,dot4,line2)
        #设置三个点
        dot1 = Dot(radius=1, color=RED)  
        dot1.move_to([-47.5,27.5,0]) 
        dot2 = Dot(radius=1, color=YELLOW)  
        dot2.move_to([-42.5,27.5,0])  
        dot3 = Dot(radius=1, color=GREEN)  
        dot3.move_to([-37.5,27.5,0])
        #镜头跟进效果 
        self.camera.frame.save_state()
        #题目出现
        text = Tex(r"\text{设函数}$f\left( x\right) =\left\{\begin{matrix}2x\sin \dfrac{1}{x}-\cos \dfrac{1}{x} & ，x\in \left[ -1,1\right] \backslash \left\{ 0\right\} \\0 &，x=0\end{matrix}\right.$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-20,20,0])
        text0 = Tex(r"\text{}$g\left( x\right) =\left\{\begin{matrix}e^x & ，0<x\leq 1\\ 0 &，x=0\\-e^{-x}&,-1\leq x\leq 0\end{matrix}\right.$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([27,20,0])
        text1 = Tex(r"\text{则下列说法正确的是()}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-35,12,0])
        
        text2 = Tex(r"$\left( A\right) f\left( x\right) $\text{与}$g\left( x\right) $\text{在}$\left[ -1,1\right] $\text{上均有第一类间断点}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22,7,0])
        text3 = Tex(r"$\left( B\right) f\left( x\right) $\text{与}$g\left( x\right)  $\text{在}$\left[ -1,1\right] $\text{上均有第二类间断点}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-22,1,0])
        text4 = Tex(r"$\left( C\right) f\left( x\right) $\text{与}$g\left( x\right) $\text{在}$\left[ -1,1\right] $\text{上均存在原函数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-24.5,-5,0])
        text5 = Tex(r"$\left( D\right) $\text{定积分}$\int _{-1}^{1}f\left( x\right) dx$\text{与}$\int _{-1}^{1}g\left( x\right) $\text{均存在}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-25,-11,0])
        self.play(Write(text),Write(text0),Write(text1),Write(text2),Write(text3),Write(text4),Write(text5),self.camera.frame.animate.scale(1))
        self.wait()
        #镜头拉回
          #分析文本
        #text100=MarkupText("<b><i>分析/解：</i></b>",color=PINK).scale(5.0).move_to([-38,12.5,0])
        self.play(Restore(self.camera.frame))
        self.play(FadeIn(dot1),run_time=0.1)
        self.play(FadeIn(dot2),run_time=0.1)
        self.play(FadeIn(dot3),run_time=0.1)
        text6 = Tex(r"\text{x=0为震荡间断点(第二类)}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([-2,12.5,0])
        self.play(Write(text6))
        text7 = Tex(r"\text{x=0为跳跃间断点(第一类)}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([32,12.5,0])
        self.play(Write(text7))
        #半透明矩阵扩展
        rectangle4=Rectangle(color=RED,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=RED,stroke_width=0).move_to([-22,7,0])
       
        rectangle5=Rectangle(color=RED,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=RED,stroke_width=0).move_to([-22,1,0])
        self.play(
            rectangle4.animate.stretch(54.0,dim=0),
            rectangle5.animate.stretch(54.0,dim=0)
        )
        rectangle6=Rectangle(color=BLUE,fill_opacity=0.0,width=35,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle6.move_to([-2,12.5,0])
        self.play(Create(rectangle6))
        text8 = Tex(r"$\int f\left( x\right) dx=\int \left( 2x\sin \dfrac{1}{x}-\cos \dfrac{1}{x}\right) dx$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([25,-5,0])
        self.play(Write(text8))
        text9 = Tex(r"$x^{2}\sin \dfrac{1}{x}+C$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-5,0])
        self.play(ReplacementTransform(text8,text9))
        self.wait(0.2)
        text10 = Tex(r"$f\left( x\right) $\text{有原函数}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([20,-5,0])
        self.play(ReplacementTransform(text9,text10))
        self.wait(0.2)
        rectangle7=Rectangle(color=BLUE,fill_opacity=0.0,width=35,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle7.move_to([32,12.5,0])
        self.play(Create(rectangle7))
        text11 = Tex(r"$g\left( x\right) $\text{没有原函数}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([32,7.5,0])
        self.play(Write(text11))
        rectangle8=Rectangle(color=RED,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=RED,stroke_width=0).move_to([-22,-5,0])
       
       
        self.play(
            rectangle8.animate.stretch(54.0,dim=0),
            
        )
        text12 = Tex(r"$f\left( x\right) $\text{和}$g\left( x\right) $\text{有界且只有有限个间断点}",color=WHITE
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,-17.5,0])
        self.play(Write(text12))
        rectangle9=Rectangle(color=GREEN,fill_opacity=0.5,width=1,height=2.8
                            ,stroke_color=GREEN,stroke_width=0).move_to([-22,-11,0])
       
       
        self.play(
            rectangle9.animate.stretch(54.0,dim=0),
            
        )

        self.wait()